sum.ts
thoward37@gmail.com/shirt[add-sum-numbers-function-new-file-sum-ts] / sum.ts
@ 5090deab
Download
Ladder Summary
- file Add a sum function to compute the sum of an array of numbers
/**
* Calculates the sum of an array of numbers.
*
* @param numbers - An array of numbers to sum.
* @returns The total sum of the numbers. Returns 0 for an empty array.
*/
export function sum(numbers: number[]): number {
return numbers.reduce((total, current) => total + current, 0);
}